package com.cndw.kungfu.controller;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;

import org.springframework.beans.BeanUtils;

import com.cndw.commons.util.BlankUtils;
import com.cndw.kungfu.comm.tencent.LogFieldType;
import com.cndw.kungfu.comm.tencent.QQDC;
import com.cndw.kungfu.config.Constants;
import com.cndw.kungfu.config.ConstantsChat;
import com.cndw.kungfu.config.ConstantsDailyItem;
import com.cndw.kungfu.config.ConstantsLevel;
import com.cndw.kungfu.config.ConstantsLog;
import com.cndw.kungfu.config.ConstantsModel;
import com.cndw.kungfu.config.ConstantsTask;
import com.cndw.kungfu.config.GoodsEffectConfig;
import com.cndw.kungfu.domain.Goods;
import com.cndw.kungfu.domain.GoodsMode;
import com.cndw.kungfu.domain.Player;
import com.cndw.kungfu.ext.LangUtil;
import com.cndw.kungfu.ext.LanguageLib;
import com.cndw.kungfu.ext.NumberProcesser;
import com.cndw.kungfu.model.Context;
import com.cndw.kungfu.model.goods.PlayerBoxs;
import com.cndw.kungfu.model.goods.domain.ModeGoodsCompound;
import com.cndw.kungfu.model.goods.domain.ModeGoodsForge;
import com.cndw.kungfu.model.goods.domain.ModeGoodsHole;
import com.cndw.kungfu.model.goods.domain.ModeGoodsInlay;
import com.cndw.kungfu.model.goods.domain.ModeGoodsStarSuit;
import com.cndw.kungfu.model.goods.domain.ModeGoodsUpgrade;
import com.cndw.kungfu.model.sys.ChatMain;
import com.cndw.kungfu.model.sys.LogServer;
import com.cndw.kungfu.vo.goodsvo.GoodsModeVO;
import com.cndw.kungfu.vo.goodsvo.GoodsVO;
import com.cndw.rpg.annotation.Controller;
import com.cndw.rpg.framework.ResponseMessage;
import com.cndw.rpg.framework.Session;

/**
 * 装备锻造
 * 
 * 
 * @author <a href="mailto:whz-work@163.com">汪洪州</a>
 * 
 * @since 1.0 Create on 2011-5-30
 */
@Controller
public class ForgeController {

	public ResponseMessage show(Session session, int type) {
		Player player = Context.getPlayerServer().getByPlayerId(session.getUid());
		QQDC.getInstance().logClick(player, LogFieldType.forget);

		return null;
	}

	/**
	 * 装备升星
	 * 
	 * @param session
	 * @param style
	 *            1包袱物品,2身上装备
	 * @param storagePlace
	 *            强化装备的存储位置
	 * @param blessingBox
	 *            祝福宝箱
	 * 
	 * @return
	 */
	public ResponseMessage upgradeStar(Session session, int style, int storagePlace, int blessingBox, int autoAsset, int autoStore, int baoFuNum) {

		if (style < 1 || style > 2 || baoFuNum < 0) {
			return ResponseMessage.ticpErrMsg(LanguageLib.get("comm.err.args"));
		}

		Player player = Context.getPlayerServer().getByPlayerId(session.getUid());
		PlayerBoxs playerBox = player.getPlayerBoxs();
		Goods goods = style == 1 ? playerBox.get(storagePlace) : playerBox.getByPostition(storagePlace);
		if (goods == null) {
			return ResponseMessage.ticpErrMsg(LanguageLib.get("comm.err.args"));
		}

		int originalLev = goods.getLevel();
		GoodsMode goodsMode = Context.getGoodsServer().getModeById(goods.getGoodsId());
		if (!goodsMode.isEquiq()) {
			return ResponseMessage.ticpErrMsg(LanguageLib.get("goods.err.mode"));
		}

		if (goodsMode.isNOForgeEquiq()) {
			return ResponseMessage.ticpErrMsg(LanguageLib.get("goods.err.cantdo"));
		}
		
		if(baoFuNum > 0 && originalLev < 9) {//九级以下不能使用升星宝符
			return null;
		}

		if (baoFuNum > ConstantsModel.rateBaofu.length - 1) {
			return ResponseMessage.ticpErrMsg(LanguageLib.get("goods.upgrade.maxbaofu"), 20);
		}

		int asset = 0;
		int punish = 0;
		// int bindType = 0;
		int goodsId = 0;
		int goodsCounts = 1;
		int level = goods.getLevel() + 1;
		boolean success = true;
		if (blessingBox > 0) { // 使用祝福包厢
			GoodsMode mode = Context.getGoodsServer().getModeById(blessingBox);
			if (goods.getLevel() >= mode.getPlayerLevel()) {
				return ResponseMessage.ticpErrMsg(LanguageLib.get("goods.upgrade.blessingbox"));
			}

			int counts = playerBox.getStackNum(blessingBox);
			if (counts < 1) {
				return ResponseMessage.ticpErrMsg(LanguageLib.get("goods.upgrade.blessing"));
			}

			level = mode.getPlayerLevel();
			goodsId = blessingBox;
			// bindType = playerBox.costGoods(blessingBox, 1);
			playerBox.costGoods(blessingBox, 1);
		} else {

			ModeGoodsUpgrade upgrade = ModeGoodsUpgrade.getByLevel(level);
			if (upgrade == null) {
				return ResponseMessage.ticpErrMsg(LanguageLib.get("goods.upgrade.max"));
			}

			if (player.getAsset() < upgrade.getAsset()) {
				return ResponseMessage.ticpErrMsg(LanguageLib.get("comm.err.asset"));
			}

			int counts = playerBox.getStackNum(upgrade.getGoodsId());
			int baoFuStackNum = playerBox.getStackNum(GoodsEffectConfig.starBaoFuId);
			if (baoFuNum > baoFuStackNum) {
				return ResponseMessage.ticpErrMsg(LanguageLib.get("goods.upgrade.less"));
			}
			if (counts < upgrade.getCounts()) {
				if (autoStore == 1) {
					if (!Context.getGoodsServer().buyStore(player, upgrade.getGoodsId(), upgrade.getCounts())) {
						return ResponseMessage.ticpErrMsg(LanguageLib.get("comm.err.gold"));
					}
				} else {
					return ResponseMessage.ticpErrMsg(LanguageLib.get("goods.upgrade.min"));
				}
			} else {
				playerBox.costGoods(upgrade.getGoodsId(), upgrade.getCounts());

			}
			if (baoFuNum > 0) {
				playerBox.costGoods(GoodsEffectConfig.starBaoFuId, baoFuNum);
			}

			asset = upgrade.getAsset();
			punish = upgrade.getPunish();
			goodsCounts = upgrade.getCounts();
			goodsId = upgrade.getGoodsId();
			player.alterAsset(-upgrade.getAsset());

			int rateAdd = ConstantsModel.rateBaofu[baoFuNum];

			success = NumberProcesser.isWinning(upgrade.getRatio() + rateAdd);
		}

		// if ((goods.getGoodsMode().getBindType() == 4 && goods.getBinding() ==
		// 0) || bindType == 1) {
		goods.setBinding(1);
		// }

		Map<String, Object> resultMap = new HashMap<String, Object>();
		if (success) {
			goods.setLevel(level);
			Context.getTaskServer().notifyToSpark(session.getUid(), ConstantsTask.spark3EquipUpgrade, 1);
			player.getDataInfo().getEveryDay().finishDailyItem(ConstantsDailyItem.upgradeStarItem);
			if (level >= 7) {
				// ChatMain.hearsayMessage(LanguageLib.get("board.equip.star",
				// player.getPlayerName(), goodsMode.getName(),
				// goods.getLevel(),
				// LangUtil.getColor(goodsMode.getColor())),ConstantsChat.cwStar);
				ChatMain.hearsayMessage(
						LanguageLib.get("board.equip.star", LangUtil.makeNameLink(player), goodsMode.getName(), goods.getLevel(),
								LangUtil.getColor(goodsMode.getColor())), ConstantsChat.cwStar);
			}
		} else {
			goods.setLevel(goods.getLevel() - punish);
			resultMap.put("errMessage", punish == 0 ? LanguageLib.get("goods.upgrade.fail1") : LanguageLib.get("goods.upgrade.fail", goods.getLevel()));
		}

		if (goods.getLevel() != originalLev) {
			Context.getGoodsServer().upgradeGoodsLevel(goods);
			goods.commitSync();
		}

		if (style == 2) {
			Context.getPlayerServer().clacProperties(player);
			resultMap.put("player", player.toPlayerVO());
			List<ModeGoodsStarSuit> suit = ModeGoodsStarSuit.getStarSuite(playerBox.getEquipList());
			resultMap.put("goodsStarSuit", suit);
			Context.getGeneralServer().addTilte(player.getPlayerId(), Constants.titleUpStar, 0);
		}

		if (autoAsset > 0 || autoStore > 0) {
			resultMap.put("gold", player.getGold());
			resultMap.put("goldBing", player.getGoldBing());
		}
		resultMap.put("asset", player.getAsset());
		resultMap.put("goods", goods.toGoodsVO());
		player.commitSync();// 提交同步

		// 添加“装备-强化”日志
		LogServer.recordLog(player, ConstantsLog.forge, 10001, goods.getId(), originalLev, goods.getGoodsMode().getName(), goods.getGoodsId(), goodsId, 0,
				goodsCounts, asset, goods.getLevel(), baoFuNum);

		return ResponseMessage.getSuccMessage(resultMap);
	}

	/**
	 * 获取升下一星级需要的材料，成功使用的装备属性
	 * 
	 * @param session
	 * @param storagePlace
	 *            需要强化的装备存储位置
	 * @return
	 */
	public ResponseMessage getNextUpgrade(Session session, int style, int useBlessing, int storagePlace) {

		if (style < 1 || style > 2) {
			return ResponseMessage.ticpErrMsg(LanguageLib.get("comm.err.args"));
		}

		Player player = Context.getPlayerServer().getByPlayerId(session.getUid());
		PlayerBoxs playerBox = player.getPlayerBoxs();
		Goods goods = style == 1 ? playerBox.get(storagePlace) : playerBox.getByPostition(storagePlace);
		if (goods == null) {
			return ResponseMessage.ticpErrMsg(LanguageLib.get("comm.err.args"));
		}

		GoodsMode goodsMode = Context.getGoodsServer().getModeById(goods.getGoodsId());
		if (!goodsMode.isEquiq()) {
			return ResponseMessage.ticpErrMsg(LanguageLib.get("goods.err.mode"));
		}

		ModeGoodsUpgrade upgrade = ModeGoodsUpgrade.getByLevel(goods.getLevel() + 1);
		if (upgrade == null) {
			return ResponseMessage.ticpErrMsg(LanguageLib.get("goods.upgrade.max"));
		}

		Map<String, Object> resultMap = new HashMap<String, Object>();
		resultMap.put("blessing", useBlessing);

		if (useBlessing == 1) {
			int maxLevel = 0;
			for (int i = 0; i < 6; i++) {
				if (playerBox.isHaveGoods(ModeGoodsUpgrade.getBlessing()[i])) {
					maxLevel = i + 4;
				}
			}

			if (maxLevel > goods.getLevel()) {
				resultMap.put("box", ModeGoodsUpgrade.getBlessing());
			}
		} else {
			Goods temp = new Goods();
			BeanUtils.copyProperties(goods, temp, new String[] { "id" });
			temp.setLevel(upgrade.getLevel());
			Context.getGoodsServer().upgradeGoodsLevel(temp);
			resultMap.put("sucGoods", temp.toGoodsVO());

			GoodsVO gemVO = Context.getGoodsServer().getModeById(upgrade.getGoodsId()).toGoodsVO();
			gemVO.setStackNum(playerBox.getStackNum(gemVO.getGoodsModeVO().getGoodsId()));
			int rateAdd = 0;
			// if (player.getVip() != null) {
			// rateAdd = player.getVip().getEquipUpgradeR();
			// }

			resultMap.put("upgrade", upgrade.clone(rateAdd));
			resultMap.put("gemGoodMode", gemVO);
			resultMap.put("hasGem", gemVO.getStackNum() >= upgrade.getCounts());
		}

		if (goods.getLevel() == 9 || goods.getLevel() == 10) {
			GoodsVO baoFuVO = Context.getGoodsServer().getModeById(GoodsEffectConfig.starBaoFuId).toGoodsVO();
			resultMap.put("baoFuVO", baoFuVO);
		}

		return ResponseMessage.getSuccMessage(resultMap);
	}

	/**
	 * 获取祝福宝箱
	 * 
	 * @param session
	 * @return
	 */
	public ResponseMessage getBlessingBox(Session session) {

		PlayerBoxs playerBoxs = Context.getPlayerServer().getByPlayerId(session.getUid()).getPlayerBoxs();

		Map<String, Object> resultMap = new HashMap<String, Object>();
		for (int i : ModeGoodsUpgrade.getBlessing()) {
			GoodsMode mode = Context.getGoodsServer().getModeById(i);
			resultMap.put(String.valueOf(mode.getPlayerLevel()), new Integer[] { mode.getGoodsId(), playerBoxs.getStackNum(i) });
		}

		return ResponseMessage.getSuccMessage(resultMap);
	}

	/**
	 * 装备追加
	 * 
	 * @param session
	 *            锻造的装备存储位置
	 * @return
	 */
	public ResponseMessage forgeGoods(Session session, int style, int level, int storagePlace, int autoAsset) {

		if (style < 1 || style > 2 || level <= 0) {
			return ResponseMessage.ticpErrMsg(LanguageLib.get("comm.err.args"));
		}

		Player player = Context.getPlayerServer().getByPlayerId(session.getUid());
		PlayerBoxs playerBox = player.getPlayerBoxs();
		Goods goods = style == 1 ? playerBox.get(storagePlace) : playerBox.getByPostition(storagePlace);
		if (goods == null || level <= goods.getForgeLevel()) {
			return ResponseMessage.ticpErrMsg(LanguageLib.get("comm.err.args"));
		}

		int originalForgeLev = goods.getForgeLevel();
		GoodsMode goodsMode = Context.getGoodsServer().getModeById(goods.getGoodsId());

		if (goodsMode.isNOForgeEquiq()) {
			return ResponseMessage.ticpErrMsg(LanguageLib.get("goods.err.cantdo"));
		}

		if (!goodsMode.isEquiq()) {
			return ResponseMessage.ticpErrMsg(LanguageLib.get("goods.err.mode"));
		}
		if (level > 30) {
			return ResponseMessage.ticpErrMsg(LanguageLib.get("goods.forge.maxlevel"));
		}

		int asset = 0;
		for (int i = goods.getForgeLevel() + 1; i <= level; i++) {
			asset += ModeGoodsForge.getForgeAsset(i);
		}

		if (player.getAsset() < asset) {
			if (autoAsset == 1) {
				if (!Context.getGoodsServer().buyAsset(player, asset)) {
					return ResponseMessage.ticpErrMsg(LanguageLib.get("comm.err.gold"));
				}
			} else {
				return ResponseMessage.ticpErrMsg(LanguageLib.get("comm.err.asset"));
			}
		}
		player.alterAsset(-asset);
		goods.setBinding(1);
		goods.setForgeLevel(level);
		goods.commitSync();
		player.commitSync();// 提交同步

		Context.getTaskServer().notifyToSpark(session.getUid(), ConstantsTask.spark4EquipForge, 1);
		player.getDataInfo().getEveryDay().finishDailyItem(ConstantsDailyItem.appendItem);

		Map<String, Object> resultMap = new HashMap<String, Object>();
		if (style == 2) {
			Context.getPlayerServer().clacProperties(player);
			resultMap.put("player", player.toPlayerVO());
		}
		resultMap.put("gold", player.getGold());
		resultMap.put("goldBing", player.getGoldBing());
		resultMap.put("asset", player.getAsset());
		resultMap.put("goods", goods.toGoodsVO());

		// 添加“装备-锻造”日志
		LogServer.recordLog(player, ConstantsLog.forge, 10002, goods.getId(), originalForgeLev, goods.getGoodsMode().getName(), goods.getGoodsId(), 0, 0,
				asset, goods.getForgeLevel(), 0);

		return ResponseMessage.getSuccMessage(resultMap);

	}

	/**
	 * 获取下一级追加需要的材料，成功使用的装备属性
	 * 
	 * @param session
	 * @param storagePlace
	 *            需要锻造的装备包袱位置
	 * @return
	 */
	public ResponseMessage getNextForge(Session session, int style, int level, int storagePlace) {

		if (style < 1 || style > 2 || level <= 0) {
			return ResponseMessage.ticpErrMsg(LanguageLib.get("comm.err.args"));
		}

		Player player = Context.getPlayerServer().getByPlayerId(session.getUid());
		PlayerBoxs playerBox = player.getPlayerBoxs();
		Goods goods = style == 1 ? playerBox.get(storagePlace) : playerBox.getByPostition(storagePlace);
		if (goods == null || level <= goods.getForgeLevel()) {
			return ResponseMessage.ticpErrMsg(LanguageLib.get("comm.err.args"));
		}

		GoodsMode goodsMode = Context.getGoodsServer().getModeById(goods.getGoodsId());
		if (!goodsMode.isEquiq()) {
			return ResponseMessage.ticpErrMsg(LanguageLib.get("goods.err.mode"));
		}

		if (level > 30) {
			return ResponseMessage.getSuccMessage("max");
		} else {
			int asset = 0;
			for (int i = goods.getForgeLevel() + 1; i <= level; i++) {
				asset += ModeGoodsForge.getForgeAsset(i);
			}

			Goods temp = new Goods();
			BeanUtils.copyProperties(goods, temp, new String[] { "id" });
			temp.setForgeLevel(level);
			Map<String, Object> resultMap = new HashMap<String, Object>();
			resultMap.put("sucGoods", temp.toGoodsVO());
			resultMap.put("asset", asset);
			return ResponseMessage.getSuccMessage(resultMap);
		}
	}

	/**
	 * 打孔
	 * 
	 * @param session
	 * @param storagePlace
	 *            打孔装备的包袱位置
	 * @return
	 */
	public ResponseMessage slotting(Session session, int style, int storagePlace, int autoAsset) {

		if (style < 1 || style > 2) {
			return ResponseMessage.ticpErrMsg(LanguageLib.get("comm.err.args"));
		}

		Player player = Context.getPlayerServer().getByPlayerId(session.getUid());
		if (player.getLevel() < ConstantsLevel.lv43GoodsSlotting) {
			return ResponseMessage.ticpErrMsg(LanguageLib.get("goods.hole.level", ConstantsLevel.lv43GoodsSlotting));
		}

		PlayerBoxs playerBox = player.getPlayerBoxs();
		Goods goods = style == 1 ? playerBox.get(storagePlace) : playerBox.getByPostition(storagePlace);
		if (goods == null) {
			return ResponseMessage.ticpErrMsg(LanguageLib.get("comm.err.args"));
		}

		GoodsMode goodsMode = Context.getGoodsServer().getModeById(goods.getGoodsId());

		if (goodsMode.isNOForgeEquiq()) {
			return ResponseMessage.ticpErrMsg(LanguageLib.get("goods.err.cantdo"));
		}

		if (!goodsMode.isEquiq()) {
			return ResponseMessage.ticpErrMsg(LanguageLib.get("goods.err.mode"));
		}

		ModeGoodsHole hole = ModeGoodsHole.get(goods.getHoleCounts() + 1);
		if (hole == null) {
			return ResponseMessage.ticpErrMsg(LanguageLib.get("goods.hole.max"));
		}

		int counts = playerBox.getStackNum(hole.getGoodsId());
		if (counts < hole.getCounts()) {
			return ResponseMessage.ticpErrMsg(LanguageLib.get("goods.hole.min"));
		}

		if (player.getAsset() < hole.getAsset()) {
			if (autoAsset == 1) {
				if (!Context.getGoodsServer().buyAsset(player, hole.getAsset())) {
					return ResponseMessage.ticpErrMsg(LanguageLib.get("comm.err.gold"));
				}
			} else {
				return ResponseMessage.ticpErrMsg(LanguageLib.get("comm.err.asset"));
			}
		}

		player.alterAsset(-hole.getAsset());

		playerBox.costGoods(hole.getGoodsId(), hole.getCounts());

		Map<String, Object> resultMap = new HashMap<String, Object>();
		if (NumberProcesser.isWinning(hole.getRatio())) {
			goods.setHoleCounts(hole.getHole());
			goods.setBinding(1);
			goods.commitSync();// 同步道具
			resultMap.put("asset", player.getAsset());
		} else {
			resultMap.put("errMessage", LanguageLib.get("goods.hole.fail"));
		}
		if (autoAsset > 0) {
			resultMap.put("gold", player.getGold());
			resultMap.put("goldBing", player.getGoldBing());
		}
		resultMap.put("goods", goods.toGoodsVO());

		player.commitSync();// 提交同步

		// 添加“装备-打孔”日志
		LogServer.recordLog(player, ConstantsLog.forge, 10003, goods.getId(), goods.getGoodsMode().getName(), goods.getGoodsId(), hole.getHole(), Context
				.getGoodsServer().getModeById(hole.getGoodsId()).getName(), hole.getCounts());

		return ResponseMessage.getSuccMessage(resultMap);
	}

	/**
	 * 获取下次打孔的材料
	 * 
	 * @param session
	 * @param storagePlace
	 *            需要打孔的装备位置
	 * @return
	 */
	public ResponseMessage getNextSlotting(Session session, int style, int storagePlace) {

		if (style < 1 || style > 2) {
			return ResponseMessage.ticpErrMsg(LanguageLib.get("comm.err.args"));
		}

		Player player = Context.getPlayerServer().getByPlayerId(session.getUid());
		if (player.getLevel() < ConstantsLevel.lv43GoodsSlotting) {
			return ResponseMessage.ticpErrMsg(LanguageLib.get("goods.hole.level", ConstantsLevel.lv43GoodsSlotting));
		}

		PlayerBoxs playerBox = player.getPlayerBoxs();
		Goods goods = style == 1 ? playerBox.get(storagePlace) : playerBox.getByPostition(storagePlace);
		if (goods == null) {
			return ResponseMessage.ticpErrMsg(LanguageLib.get("comm.err.args"));
		}

		GoodsMode goodsMode = Context.getGoodsServer().getModeById(goods.getGoodsId());
		if (!goodsMode.isEquiq()) {
			return ResponseMessage.ticpErrMsg(LanguageLib.get("goods.err.mode"));
		}

		ModeGoodsHole hole = ModeGoodsHole.get(goods.getHoleCounts() + 1);
		if (hole == null) {
			return ResponseMessage.ticpErrMsg(LanguageLib.get("goods.hole.max"));
		}

		Map<String, Object> resultMap = new HashMap<String, Object>();

		Goods temp = new Goods();
		BeanUtils.copyProperties(goods, temp, new String[] { "id" });
		temp.setHoleCounts(hole.getHole());
		GoodsVO gemVO = Context.getGoodsServer().getModeById(hole.getGoodsId()).toGoodsVO();
		gemVO.setStackNum(playerBox.getStackNum(gemVO.getGoodsModeVO().getGoodsId()));
		resultMap.put("hole", hole);
		resultMap.put("gemGoodMode", gemVO);
		resultMap.put("sucGoods", temp.toGoodsVO());
		resultMap.put("hasGem", gemVO.getStackNum() >= hole.getCounts());
		return ResponseMessage.getSuccMessage(resultMap);
	}

	/**
	 * 合成宝石
	 * 
	 * @param session
	 * @param type
	 * @param level
	 * @param num
	 * @param storage
	 * 			宝石的存储位置
	 * @param autoAsset
	 * @param sNum  概率合成用于合成宝石的数量
	 * @return
	 */
	public ResponseMessage compoundGem(Session session, int type, int level, int num, int storage, int autoAsset, int sNum) {
		if (sNum < 0 || sNum > 5 || (sNum > 0 && num > 1)) {//概率合成只能合成一个
			return null;
		}
		if (sNum > 0 && (type == 1 || type == 4)) {
			return null;
		}
		Player player = Context.getPlayerServer().getByPlayerId(session.getUid());
		PlayerBoxs playerBox = player.getPlayerBoxs();
		if (!playerBox.checkBlack(1)) {
			return ResponseMessage.ticpErrMsg(LanguageLib.get("comm.player.boxmin", 1));
		}

		Goods goods = playerBox.get(storage);
		if (goods == null || num <= 0 || level <= 0) {
			return ResponseMessage.ticpErrMsg(LanguageLib.get("comm.err.args"));
		}

		GoodsMode s = goods.getGoodsMode();

		if (s.isNOForgeEquiq()) {
			return ResponseMessage.ticpErrMsg(LanguageLib.get("goods.err.cantdo"));
		}

		if (s.isEquiq()) {
			return ResponseMessage.ticpErrMsg(LanguageLib.get("comm.err.args"));
		}

		List<Object[]> config = null;
		if (type == 2 || type == 3) { // 宝石碎片和宝石
			config = ModeGoodsCompound.getConfigList(s.getPlayerLevel(), goods.getGoodsId()); // 获取宝石配置
			if (BlankUtils.isBlank(config)) {
				return ResponseMessage.ticpErrMsg(LanguageLib.get("goods.compound.maxLevel"));
			}
		} else if (type == 1 || type == 4) { // 强化石和附星宝箱
			config = ModeGoodsCompound.getConfigList(goods.getGoodsId());
			if (BlankUtils.isBlank(config)) {
				return ResponseMessage.ticpErrMsg(LanguageLib.get("goods.compound.maxLevel"));
			}
		}

		int asset = 0;
		int counts = 0;
		GoodsVO goodsVO = null;
		for (int i = config.size() - 1; i >= 0; i--) {
			int lvl = Integer.parseInt(config.get(i)[0].toString());
			if (level == lvl) {
				counts = Integer.parseInt(config.get(i)[1].toString());
				asset = Integer.parseInt(config.get(i)[2].toString());
				goodsVO = (GoodsVO) config.get(i)[3];
			} else if (goods.getGoodsMode().getPlayerLevel() < lvl && lvl < level) {
				asset += counts * Integer.parseInt(config.get(i)[2].toString());
				counts *= Integer.parseInt(config.get(i)[1].toString());
			}
		}

		if (asset <= 0 || counts <= 0) {
			return ResponseMessage.ticpErrMsg(LanguageLib.get("comm.err.args"));
		}

		asset *= num;
		boolean isRate = sNum > 0;//是否概率合成
		counts = isRate ? sNum : counts * num;

		int hasCounts = playerBox.getStackNum(goods.getGoodsId());
		if (hasCounts < counts) {
			return ResponseMessage.ticpErrMsg(LanguageLib.get("goods.compound.min", counts));
		}

		if (player.getAsset() < asset) {
			if (autoAsset == 1) {
				if (!Context.getGoodsServer().buyAsset(player, asset)) {
					return ResponseMessage.ticpErrMsg(LanguageLib.get("comm.err.gold"));
				}
			} else {
				return ResponseMessage.ticpErrMsg(LanguageLib.get("comm.err.asset"));
			}
		}

		boolean suc = true;
		if (!BlankUtils.isBlank(goodsVO)) {

			// 检查给的物品的绑定状态
			GoodsModeVO goodsModel = goodsVO.getGoodsModeVO();
			playerBox.costGoods(goods.getGoodsId(), counts);
			if (isRate) {//是否概率合成
				suc = NumberProcesser.isWinning(ConstantsModel.compoundGemRate[sNum]);
			}
			if (suc) {
				Context.getGoodsServer().giveGoodsBing(session.getUid(), goodsModel.getGoodsId(), num, 1);
			}

			player.alterAsset(-asset);
			if (type == 1) {
				// player.getDataInfo().getEveryDay().finishDailyItem(ConstantsDailyItem.compoundUpGemItem);
			} else if (type == 2 || type == 3) {
//				player.getDataInfo().getEveryDay().finishDailyItem(ConstantsDailyItem.compoundGemItem);
			}
			player.commitSync();// 提交同步

			// 添加“装备-宝石合成”日志
			if (goodsModel != null) {
				LogServer.recordLog(player, ConstantsLog.forge, 10008, asset, goods.getGoodsMode().getName(), counts, suc, goodsModel.getName(), num);
			}
		}
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("asset", player.getAsset());
		map.put("gold", player.getGold());
		map.put("goldBing", player.getGoldBing());
		map.put("suc", suc);

		return ResponseMessage.getSuccMessage(map);
	}

	/**
	 * 获取合成的配置
	 * 
	 * @param session
	 * @param storage
	 * @return
	 */
	public ResponseMessage getCompoundGoods(Session session, int type, int storage) {

		Player player = Context.getPlayerServer().getByPlayerId(session.getUid());
		PlayerBoxs playerBox = player.getPlayerBoxs();
		Goods goods = playerBox.get(storage);
		if (goods == null) {
			return ResponseMessage.ticpErrMsg(LanguageLib.get("comm.err.args"));
		}

		GoodsMode s = goods.getGoodsMode();
		if (s.isEquiq()) {
			return ResponseMessage.ticpErrMsg(LanguageLib.get("comm.err.args"));
		}

		List<Object[]> config = null;
		if (type == 2 || type == 3) { // 宝石碎片和宝石
			config = ModeGoodsCompound.getConfigList(s.getPlayerLevel(), goods.getGoodsId()); // 获取宝石配置
			if (BlankUtils.isBlank(config)) {
				return ResponseMessage.ticpErrMsg(LanguageLib.get("goods.compound.maxLevel"));
			}
		} else if (type == 1 || type == 4) { // 强化石和附星宝箱
			config = ModeGoodsCompound.getConfigList(goods.getGoodsId());
			if (BlankUtils.isBlank(config)) {
				return ResponseMessage.ticpErrMsg(LanguageLib.get("goods.compound.maxLevel"));
			}
		}

		return ResponseMessage.getSuccMessage(config);
	}

	/**
	 * 过滤所有宝石和碎片
	 * 
	 * @param session
	 * @return
	 */
	public ResponseMessage getCompoundGems(Session session) {

		Player player = Context.getPlayerServer().getByPlayerId(session.getUid());
		Set<Integer> gemSet = ModeGoodsInlay.getInlayMap().keySet(); // 所有宝石
		Set<Integer> patchSet = ModeGoodsCompound.get(0).getResultMap().keySet();// 所有碎片
		Set<Integer> boxSet = ModeGoodsCompound.getBoxMap().keySet(); // 所有附星宝箱
		List<Integer> goodsIds = new ArrayList<Integer>();
		goodsIds.addAll(gemSet);
		goodsIds.addAll(patchSet);
		goodsIds.addAll(boxSet);
		// for (Integer g : ModeGoodsCompound.goods) {// 所有强化石
		// goodsIds.add(g);
		// }

		Map<Integer, List<GoodsVO>> goodsVoMap = new HashMap<Integer, List<GoodsVO>>();
		PlayerBoxs playerBoxs = player.getPlayerBoxs();
		synchronized (playerBoxs) {
			for (Goods goods : playerBoxs.getBoxsGoods()) {
				if (!playerBoxs.isLocked(goods.getStoragePlace()) && goodsIds.contains(goods.getGoodsId())) {

					// 类型3碎片,类型2宝石，类型1强化石
					Integer key = null;
					if (boxSet.contains(goods.getGoodsId())) {
						key = 4;
					} else if (patchSet.contains(goods.getGoodsId())) {
						key = 3;
					} else if (gemSet.contains(goods.getGoodsId())) {
						key = 2;
					} else {
						key = 1;
					}
					if (!goodsVoMap.containsKey(key)) {
						goodsVoMap.put(key, new ArrayList<GoodsVO>());
					}
					GoodsVO vo = goods.toGoodsVO();
					vo.getGoodsModeVO().setValueA(key);// 用来临时记录物品类型
					vo.setStackNum(playerBoxs.getStackNum(goods.getGoodsId()));//去掉被锁定的物品
					goodsVoMap.get(key).add(vo);
				}
			}
		}

		return ResponseMessage.getSuccMessage(goodsVoMap);
	}

	/**
	 * 镶嵌
	 * 
	 * @param session
	 * @param storage
	 *            装备存储位置
	 * @param gemStorage
	 *            宝石存储位置
	 * @return
	 */
	public ResponseMessage inlay(Session session, int style, int storage, int first, int second, int third, int fourth, int fifth) {

		if (style < 1 || style > 2) {
			return ResponseMessage.ticpErrMsg(LanguageLib.get("comm.err.args"));
		}

		Player player = Context.getPlayerServer().getByPlayerId(session.getUid());
		if (player.getLevel() < ConstantsLevel.lv43GoodsInlay) {
			return ResponseMessage.ticpErrMsg(LanguageLib.get("goods.inlay.level", ConstantsLevel.lv43GoodsInlay));
		}

		PlayerBoxs playerBox = player.getPlayerBoxs();
		Goods goods = style == 1 ? playerBox.get(storage) : playerBox.getByPostition(storage);
		if (goods == null) {
			return ResponseMessage.ticpErrMsg(LanguageLib.get("comm.err.args"));
		}

		if (!goods.getGoodsMode().isEquiq()) {
			return ResponseMessage.ticpErrMsg(LanguageLib.get("goods.err.mode"));
		}

		int[] gems = new int[] { first, second, third, fourth, fifth };

		int asset = 0;
		List<Integer> types = new ArrayList<Integer>(goods.getGemType());
		Map<Integer, Integer> goodsMap = new HashMap<Integer, Integer>();
		StringBuilder sb = new StringBuilder();
		for (int i = 0, j = gems.length; i < j; i++) {
			if (gems[i] > 0) {
				int hole = i + 1;
				Goods gem = playerBox.get(gems[i]);
				if (BlankUtils.isBlank(gem)) {
					return ResponseMessage.ticpErrMsg(LanguageLib.get("comm.err.args"));
				}

				// 检查是否是宝石物品
				if (!ModeGoodsInlay.getInlayMap().keySet().contains(gem.getGoodsId())) {
					return ResponseMessage.ticpErrMsg(LanguageLib.get("goods.inlay.gem"));
				}

				// 检查该位置的空是否已经打通
				if (hole > goods.getHoleCounts()) {
					return ResponseMessage.ticpErrMsg(LanguageLib.get("goods.inlay.slotting"));
				}

				// 检查该位置是否已经镶嵌过宝石
				if (goods.checkContainGem(hole)) {
					return ResponseMessage.ticpErrMsg(LanguageLib.get("goods.inlay.exsit1"));
				}

				// 检查是否镶嵌过同样类型的宝石,并且检查本次传进来的宝石是否有重复！！！！！
				int type = ModeGoodsInlay.get(gem.getGoodsId()).getType();
				if (types.contains(type)) {
					return ResponseMessage.ticpErrMsg(LanguageLib.get("goods.inlay.exsit"));
				} else {
					types.add(type);
				}

				goodsMap.put(hole, gem.getGoodsId());
				asset += ModeGoodsInlay.getRequiredMoney(gem.getGoodsMode().getPlayerLevel());
				if (sb.length() > 0) {
					sb.append(',').append(gem.getGoodsId()).append(':').append(gem.getGoodsMode().getName());
				} else {
					sb.append(gem.getGoodsId()).append(':').append(gem.getGoodsMode().getName());
				}
			}
		}

		if (player.getAsset() < asset) {
			// if (autoAsset == 1) {
			// if (!buyAsset(player, asset)) {
			// return
			// ResponseMessage.ticpErrMsg(LanguageLib.get("comm.err.gold"));
			// }
			// } else {
			return ResponseMessage.ticpErrMsg(LanguageLib.get("comm.err.asset"));
			// }
		}

		// 更新数据
		player.alterAsset(-asset);
		// int bindType = goods.getBinding();
		for (Integer hole : goodsMap.keySet()) {
			int goodsId = goodsMap.get(hole);
			goods.updateGem(hole, goodsId);
			playerBox.costGoods(goodsId, 1);
			// if (bindType == 0 && tmpType > 0) {
			// bindType = 1;
			// }
		}
		goods.setBinding(1);// 绑定状态.

		Map<String, Object> resultMap = new HashMap<String, Object>();
		resultMap.put("goods", goods.toGoodsVO());
		if (style == 1) {
			resultMap.put("asset", player.getAsset());
		} else if (style == 2) {
			Context.getPlayerServer().clacProperties(player);
			resultMap.put("player", player.toPlayerVO());
		}

		goods.commitSync();// 同步道具
		player.commitSync();

		Context.getTaskServer().notifyToSpark(session.getUid(), ConstantsTask.spark36Slotting, 1);

		// 添加“装备-镶嵌”日志
		LogServer.recordLog(player, ConstantsLog.forge, 10004, goods.getId(), goods.getGoodsMode().getName(), goods.getGoodsId(), goodsMap.size(),
				sb.toString(), asset);

		return ResponseMessage.getSuccMessage(resultMap);
	}

	/**
	 * 获取所有可镶嵌的宝石
	 * 
	 * @param session
	 * @return
	 */
	public ResponseMessage getInlayGem(Session session) {
		Player player = Context.getPlayerServer().getByPlayerId(session.getUid());
		if (player.getLevel() < ConstantsLevel.lv43GoodsInlay) {
			return ResponseMessage.ticpErrMsg(LanguageLib.get("goods.inlay.level", ConstantsLevel.lv43GoodsInlay));
		}

		Map<Integer, Object[]> gemMap = new HashMap<Integer, Object[]>();
		for (Integer goodsId : ModeGoodsInlay.getInlayMap().keySet()) {
			GoodsMode mode = Context.getGoodsServer().getModeById(goodsId);
			gemMap.put(goodsId, new Object[] { ModeGoodsInlay.getInlayMap().get(goodsId).getType(), ModeGoodsInlay.getRequiredMoney(mode.getPlayerLevel()) });
		}
		return ResponseMessage.getSuccMessage(gemMap);
	}

	/**
	 * 拆卸
	 * 
	 * @param session
	 * @param storage
	 * @param hole
	 * @return
	 */
	public ResponseMessage dismantle(Session session, int style, int storage, int hole) {

		if (style < 1 || style > 2) {
			return ResponseMessage.ticpErrMsg(LanguageLib.get("comm.err.args"));
		}

		Player player = Context.getPlayerServer().getByPlayerId(session.getUid());
		if (player.getLevel() < ConstantsLevel.lv43GoodsDismantle) {
			return ResponseMessage.ticpErrMsg(LanguageLib.get("goods.dismantle.level", ConstantsLevel.lv43GoodsDismantle));
		}

		PlayerBoxs playerBox = player.getPlayerBoxs();
		Goods goods = style == 1 ? playerBox.get(storage) : playerBox.getByPostition(storage);
		if (goods == null) {
			return ResponseMessage.ticpErrMsg(LanguageLib.get("comm.err.args"));
		}

		if (!goods.getGoodsMode().isEquiq()) {
			return ResponseMessage.ticpErrMsg(LanguageLib.get("goods.err.mode"));
		}

		if (BlankUtils.isBlank(goods.getGemMap()) || !goods.getGemMap().containsKey(hole)) {
			return ResponseMessage.ticpErrMsg(LanguageLib.get("comm.err.args"));
		}

		int counts = playerBox.getStackNum(GoodsEffectConfig.dismantle);
		if (counts < 1) {
			return ResponseMessage.ticpErrMsg(LanguageLib.get("goods.dismantle.err"));
		}

		if (!playerBox.checkBlack(1)) {
			return ResponseMessage.ticpErrMsg(LanguageLib.get("comm.player.boxmin", 1));
		}

		// 更新数据
		GoodsMode mode = Context.getGoodsServer().getModeById(goods.getGemMap().get(hole));
		if (BlankUtils.isBlank(mode)) {
			return ResponseMessage.ticpErrMsg(LanguageLib.get("comm.err.args"));
		}

		int asset = ModeGoodsInlay.getRequiredMoney(mode.getPlayerLevel());
		if (player.getAsset() < asset) {
			// if (autoAsset == 1) {
			// if (!buyAsset(player, asset)) {
			// return
			// ResponseMessage.ticpErrMsg(LanguageLib.get("comm.err.gold"));
			// }
			// } else {
			return ResponseMessage.ticpErrMsg(LanguageLib.get("comm.err.asset"));
			// }
		}

		goods.updateGem(hole, 0);
		player.alterAsset(-asset); // 和镶嵌用的一样的配置
		playerBox.costGoods(GoodsEffectConfig.dismantle, 1);
		// 拆卸物品綁定狀態按照當前物品
		Context.getGoodsServer().giveGoodsBing(session.getUid(), mode.getGoodsId(), 1, 1);

		Map<String, Object> resultMap = new HashMap<String, Object>();
		resultMap.put("goods", goods.toGoodsVO());
		if (style == 1) {
			resultMap.put("asset", player.getAsset());
		} else if (style == 2) {
			Context.getPlayerServer().clacProperties(player);
			resultMap.put("player", player.toPlayerVO());
		}

		goods.commitSync();// 道具同步
		player.commitSync();// 提交同步

		// 添加“装备-拆卸”日志
		LogServer.recordLog(player, ConstantsLog.forge, 10007, goods.getId(), goods.getGoodsMode().getName(), goods.getGoodsId(),
				ModeGoodsInlay.getRequiredMoney(mode.getPlayerLevel()), mode.getGoodsId(), mode.getName());

		return ResponseMessage.getSuccMessage(resultMap);
	}

	/**
	 * 获取拆卸的消耗和道具
	 * 
	 * @param session
	 * @param storage
	 * @param hole
	 * @return
	 */
	public ResponseMessage getDismantle(Session session, int style, int storage, int hole) {

		if (style < 1 || style > 2) {
			return ResponseMessage.ticpErrMsg(LanguageLib.get("comm.err.args"));
		}

		Player player = Context.getPlayerServer().getByPlayerId(session.getUid());
		if (player.getLevel() < ConstantsLevel.lv43GoodsDismantle) {
			return ResponseMessage.ticpErrMsg(LanguageLib.get("goods.dismantle.level", ConstantsLevel.lv43GoodsDismantle));
		}

		PlayerBoxs playerBox = player.getPlayerBoxs();
		Goods goods = style == 1 ? playerBox.get(storage) : playerBox.getByPostition(storage);
		if (goods == null) {
			return ResponseMessage.ticpErrMsg(LanguageLib.get("comm.err.args"));
		}

		if (!goods.getGoodsMode().isEquiq()) {
			return ResponseMessage.ticpErrMsg(LanguageLib.get("goods.err.mode"));
		}

		if (BlankUtils.isBlank(goods.getGemMap()) || !goods.getGemMap().containsKey(hole)) {
			return ResponseMessage.ticpErrMsg(LanguageLib.get("comm.err.args"));
		}

		int counts = playerBox.getStackNum(GoodsEffectConfig.dismantle);

		Map<String, Object> resultMap = new HashMap<String, Object>();
		GoodsMode mode = Context.getGoodsServer().getModeById(goods.getGemMap().get(hole));
		GoodsMode dismantleMode = Context.getGoodsServer().getModeById(GoodsEffectConfig.dismantle);
		resultMap.put("asset", mode == null ? 0 : 1000 * mode.getPlayerLevel());
		resultMap.put("goods", dismantleMode.toGoodsVO());
		resultMap.put("hasGoods", counts >= 1);

		return ResponseMessage.getSuccMessage(resultMap);
	}

	/**
	 * 溶化
	 * 
	 * @param first
	 *            第一件装备的包袱位置
	 * @param second
	 *            第二件装备的包袱位置
	 * @param third
	 *            第三件装备的包袱位置
	 * @param fourth
	 *            第四件装备的包袱位置
	 * @param fifth
	 *            第五件装备的包袱位置
	 * @return
	 */
	public ResponseMessage solute(Session session, int first, int second, int third, int fourth, int fifth) {

		int asset = 0;
		int[] storages = new int[] { first, second, third, fourth, fifth };
		Player player = Context.getPlayerServer().getByPlayerId(session.getUid());
		if (player.getLevel() < ConstantsLevel.lv36GoodsSolute) {
			return ResponseMessage.ticpErrMsg(LanguageLib.get("goods.solute.level", ConstantsLevel.lv36GoodsSolute));
		}
		if (player.getDataInfo().isGoodsLock()) {
			return ResponseMessage.ticpErrMsg(LanguageLib.get("player.pass.lockctrl"));
		}
		PlayerBoxs playerBox = player.getPlayerBoxs();

		// 判断物品有没有白装
		List<Goods> goodsList = new ArrayList<Goods>();
		for (int storage : storages) {
			Goods goods = playerBox.get(storage);
			if (!BlankUtils.isBlank(goods) && goods.getGoodsMode().isEquiq()) {
				if (goods.getGoodsMode().getColor() == 0) {
					return ResponseMessage.ticpErrMsg(LanguageLib.get("goods.solute.color"));
				} else {
					goodsList.add(goods);
				}
			}
		}

		if (BlankUtils.isBlank(goodsList)) {
			return ResponseMessage.ticpErrMsg(LanguageLib.get("comm.err.args"));
		}

		// 溶化物品
		StringBuilder logSB = new StringBuilder();
		Map<String, Integer> goodsMap = new HashMap<String, Integer>();
		for (Goods goods : goodsList) {
			goods = playerBox.remove(goods.getStoragePlace());
			if (!BlankUtils.isBlank(goods)) {
				int color = ConstantsModel.soluteColor[goods.getGoodsMode().getColor()];
				float suit = ConstantsModel.soluteSuit[goods.getGoodsMode().getClassId() > 0 ? 1 : 0];
				for (int i = 0, j = ConstantsModel.soluteLevel.length; i < j; i++) {
					if (goods.getGoodsMode().getPlayerLevel() <= ConstantsModel.soluteLevel[i]) {
						asset += ((int) (color * suit) + i + 1);
						break;
					}
				}

				if (goodsMap.containsKey(goods.getGoodsMode().getName())) {
					goodsMap.put(goods.getGoodsMode().getName(), goodsMap.get(goods.getGoodsMode().getName()) + 1);
				} else {
					goodsMap.put(goods.getGoodsMode().getName(), 1);
				}
				logSB.append(goods.getGoodsMode().getName()).append(",").append(goods.getId()).append(",").append(goods.getLevel()).append(";");
			}
		}

		player.alterGoldTicke(asset);
		player.commitSync();// 提交同步

		StringBuilder sb = new StringBuilder();
		Iterator<Entry<String, Integer>> iterator = goodsMap.entrySet().iterator();
		while (iterator.hasNext()) {
			Entry<String, Integer> entry = iterator.next();
			sb.append(entry.getKey()).append('*').append(entry.getValue()).append(';');
		}

		// 添加“装备-熔炼”日志
		LogServer.recordLog(player, ConstantsLog.forge, 10009, logSB.toString(), asset, sb.toString());

		return ResponseMessage.getSuccMessage(player.getGoldTicke());
	}

	/**
	 * 合铸装备 继承
	 * 
	 * @param session
	 * @param mainStorage
	 *            主装备的包袱位置
	 * @param secondStorage
	 *            副装备的包袱位置
	 * @return
	 */
	public ResponseMessage alloying(Session session, int style, int mainStorage, int seStyle, int secondStorage, int autoStore) {

		if (style < 1 || style > 2) {
			return ResponseMessage.ticpErrMsg(LanguageLib.get("comm.err.args"));
		}

		Player player = Context.getPlayerServer().getByPlayerId(session.getUid());
		if (player.getLevel() < ConstantsLevel.lv12GoodsAlloying) {
			return ResponseMessage.ticpErrMsg(LanguageLib.get("goods.alloying.level", ConstantsLevel.lv12GoodsAlloying));
		}

		PlayerBoxs playerBox = player.getPlayerBoxs();
		Goods mainGoods = style == 1 ? playerBox.get(mainStorage) : playerBox.getByPostition(mainStorage);
		Goods secondGoods = seStyle == 1 ? playerBox.get(secondStorage) : playerBox.getByPostition(secondStorage);



		if (mainGoods == null || secondGoods == null || !mainGoods.getGoodsMode().isEquiq() || !secondGoods.getGoodsMode().isEquiq()) {
			return ResponseMessage.ticpErrMsg(LanguageLib.get("comm.err.args"));
		}
		if (mainGoods.getGoodsMode().isNOForgeEquiq() || secondGoods.getGoodsMode().isNOForgeEquiq()) {
			return ResponseMessage.ticpErrMsg(LanguageLib.get("goods.err.cantdo"));
		}	

		if (mainGoods.getLevel() >= secondGoods.getLevel()) {
			return ResponseMessage.ticpErrMsg(LanguageLib.get("goods.alloying.errlevel"));
		}

		// if (mainGoods.getGoodsMode().getGoodTypeId() !=
		// secondGoods.getGoodsMode().getGoodTypeId()) {
		// return
		// ResponseMessage.ticpErrMsg(LanguageLib.get("goods.alloying.position"));
		// }

		int counts = playerBox.getStackNum(103096);
		if (counts < 1) {
			if (autoStore == 1) {
				if (!Context.getGoodsServer().buyStore(player, 103096, 1)) {
					return ResponseMessage.ticpErrMsg(LanguageLib.get("comm.err.gold"));
				}
			} else {
				return ResponseMessage.ticpErrMsg(LanguageLib.get("goods.alloying.err"));
			}
		} else {
			// 消耗继承石
			playerBox.costGoods(103096, 1);
		}

		// 继承追加
		if (mainGoods.getForgeLevel() < secondGoods.getForgeLevel()) {
			mainGoods.setForgeLevel(secondGoods.getForgeLevel());
		}

		// 继承星级
		if (mainGoods.getLevel() < secondGoods.getLevel()) {
			mainGoods.setLevel(secondGoods.getLevel());
			Context.getGoodsServer().upgradeGoodsLevel(mainGoods);
		}

		// 继承绑定
		// if (secondGoods.getBinding() == 1) {
		mainGoods.setBinding(1);
		// }
		mainGoods.commitSync();// 同步道具

		// 处理副装备
		secondGoods.setLevel(0);
		secondGoods.setForgeLevel(0);
		Context.getGoodsServer().upgradeGoodsLevel(secondGoods);
		secondGoods.commitSync();

		Map<String, Object> resultMap = new HashMap<String, Object>();
		resultMap.put("gold", player.getGold());
		resultMap.put("goldBing", player.getGoldBing());
		resultMap.put("goods", mainGoods.toGoodsVO());
		resultMap.put("fuGoods", secondGoods.toGoodsVO());
		if (style == 2) {
			Context.getPlayerServer().clacProperties(player);
			resultMap.put("player", player.toPlayerVO());
		}

		Context.getTaskServer().notifyToSpark(session.getUid(), ConstantsTask.spark30Alloying, 1);

		// 添加“门派-合铸”日志
		LogServer.recordLog(player, ConstantsLog.forge, 10010, mainGoods.getGoodsMode().getName(), mainGoods.getGoodsId(), mainGoods.getId(), secondGoods
				.getGoodsMode().getName(), secondGoods.getGoodsId(), secondGoods.getId(), mainGoods.getLevel(), mainGoods.getGem(), mainGoods.getHoleCounts(),
				mainGoods.getForgeLevel());

		return ResponseMessage.getSuccMessage(resultMap);
	}

	/**
	 * 预览合铸之后的成品
	 * 
	 * @param session
	 * @param mainStorage
	 * @param secondStorage
	 * @return
	 */
	public ResponseMessage getAlloying(Session session, int style, int mainStorage, int seStyle, int secondStorage) {

		if (style < 1 || style > 2) {
			return ResponseMessage.ticpErrMsg(LanguageLib.get("comm.err.args"));
		}

		Player player = Context.getPlayerServer().getByPlayerId(session.getUid());

		PlayerBoxs playerBox = player.getPlayerBoxs();
		Goods mainGoods = style == 1 ? playerBox.get(mainStorage) : playerBox.getByPostition(mainStorage);
		Goods secondGoods = seStyle == 1 ? playerBox.get(secondStorage) : playerBox.getByPostition(secondStorage);
		if (mainGoods == null || secondGoods == null || !mainGoods.getGoodsMode().isEquiq() || !secondGoods.getGoodsMode().isEquiq()) {
			return ResponseMessage.ticpErrMsg(LanguageLib.get("comm.err.args"));
		}

		if (mainGoods.getLevel() >= secondGoods.getLevel()) {
			return ResponseMessage.ticpErrMsg(LanguageLib.get("goods.alloying.errlevel"));
		}

		// if (mainGoods.getGoodsMode().getGoodTypeId() !=
		// secondGoods.getGoodsMode().getGoodTypeId()) {
		// return
		// ResponseMessage.ticpErrMsg(LanguageLib.get("goods.alloying.position"));
		// }

		Goods temp = new Goods();
		BeanUtils.copyProperties(mainGoods, temp);

		// 继承追加
		if (temp.getForgeLevel() < secondGoods.getForgeLevel()) {
			temp.setForgeLevel(secondGoods.getForgeLevel());
		}

		// 继承星级
		if (temp.getLevel() < secondGoods.getLevel()) {
			temp.setLevel(secondGoods.getLevel());
			Context.getGoodsServer().upgradeGoodsLevel(temp);
		}

		// 继承绑定
		if (secondGoods.getBinding() == 1) {
			temp.setBinding(1);
		}

		Map<String, Object> resultMap = new HashMap<String, Object>();
		resultMap.put("result", temp.toGoodsVO());
		resultMap.put("goods", Context.getGoodsServer().getModeById(103096).toGoodsVO());
		resultMap.put("counts", player.getPlayerBoxs().getStackNum(103096));
		return ResponseMessage.getSuccMessage(resultMap);
	}
}
